package com.scf.loanmanage.rabbitmq;

import com.scf.loanmanage.configuration.RabbitmqUtil;
import com.scf.loanmanage.dao.RepaymentMapper;
import com.scf.loanmanage.dao.RepaymentRegisteredMapper;
import com.scf.loanmanage.entity.Repayment;
import com.scf.loanmanage.service.ServiceImp.RepaymentRegisteredImpl;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class BusinessComsumer {
    @Resource
    RepaymentRegisteredMapper repaymentRegisteredMapper;
    @Resource
    RepaymentMapper repaymentMapper;
    @Resource
    RepaymentRegisteredImpl repaymentRegistered;
    //监听多个消息队列
    @RabbitListener(queues = "插件延迟的消息队列")
    public void received(Message message, RabbitmqUtil rabbitmqUtil) {

        System.out.println("执行还款");
        Repayment repayment = repaymentMapper.selectByReid(rabbitmqUtil.getReid());
        repaymentRegisteredMapper.insertByreid(null, rabbitmqUtil.getD(), null,repayment.getBorrowed(),rabbitmqUtil.getMoney(), 500.00, 10, 0.0,"已还清",rabbitmqUtil.getReid());
                    Double Interestpayable = repaymentRegistered.selectReidzongjine(rabbitmqUtil.getReid());
                    Double exInterest = repaymentRegistered.selectReidzonglixi(rabbitmqUtil.getReid());
                    System.out.println("要还 的金额是："+Interestpayable+"利息是--"+exInterest);
                    repaymentMapper.update(rabbitmqUtil.getReid(),Interestpayable,exInterest);
    }

}
